<template>
  <div>
    <el-table :data="adminsListData.admins" border style="width: 100%" >
      <el-table-column prop="account" label="账号" align='center'> </el-table-column>
      <el-table-column prop="password" label="密码" align='center'> </el-table-column>
      <el-table-column label="权限" align='center'>
        <template slot-scope="scope">
            <p v-if="scope.row.power == 2">普通管理员</p>
          </el-popover>
        </template>
      </el-table-column>
     <el-table-column label="状态" align='center'>
        <template slot-scope="scope">
            <p v-if="scope.row.state == 1">正常</p>
             <p v-else>已冻结</p>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="操作" align='center'>
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="bloackingAdmins(scope.row._id)"
            v-if="scope.row.state == 1"
            :plain="true"
          >
            冻结
          </el-button>
          <el-button
            size="mini"
            v-else
            @click="exposureFreeze(scope.row._id)"
            :plain="true"
          >
            解冻
          </el-button>
          <el-button
            size="mini"
            type="danger"
            @click="$router.push('updatePassword/' + scope.row._id)"
            >修改密码</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5, 6, 7, 8]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="adminsListData.total"
    >
    </el-pagination>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const {
  mapState: AdminsMapState,
  mapMutations: AdminsMapMutations,
  mapActions: AdminsMapActions,
} = createNamespacedHelpers("admins");
export default {
  data() {
    return {};
  },
  mounted() {
    this.getAdmins();
  },
  computed: {
    ...AdminsMapState(["adminsListData", "pageSize", "currentPage"]),
  },
  methods: {
    ...AdminsMapActions(["getAdmins", "freezeAdmins", "exposureFreezeAdmins"]),
    ...AdminsMapMutations(["changepageSize", "changecurrentPage"]),

    handleSizeChange(val) {
      this.changepageSize(val);
      this.getAdmins();
    },
    handleCurrentChange(val) {
      this.changecurrentPage(val);
      this.getAdmins();
    },
    bloackingAdmins(_id) {
      this.$message("冻结管理员账户成功");
      this.freezeAdmins(_id);
      this.getAdmins();
    },
    exposureFreeze(_id) {
      this.$message("解除冻结成功");
      this.exposureFreezeAdmins(_id), this.getAdmins();
    },
  },
};
</script>
